package com.xiaor.rssfigure.controller;

import com.xiaor.rssfigure.service.FigureService;
import com.xiaor.rssmodel.model.Figure;
import com.xiaor.rssutils.pager.Page;
import com.xiaor.rssutils.result.ResultInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/figure")
public class FigureController {
    @Autowired
    private FigureService figureService;
    @Autowired
    private ResultInfo info;
    private static Logger logger = LoggerFactory.getLogger(FigureController.class);

    @ModelAttribute
    public void init() {
        info.clear();
        logger.info("/figure");
    }

    @GetMapping("/find_by_name")
    ResultInfo findByName(Figure figure) {
        try {
            info.setData(figureService.findByName(figure));
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("findAll|查询失败");
        }
        return info;
    }

    @GetMapping("/find_all")
    ResultInfo findAll(Page page) {
        try {
            info.setData(figureService.findAll(page));
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("findAll|查询失败");
        }
        return info;
    }

    @GetMapping("/find_simple_all")
    ResultInfo findSimpleAll(Page page) {
        try {
            info.setData(figureService.findSimpleAll(page));
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("findSimpleAll|查询失败");
        }
        return info;
    }
}
